@model CaipuGuanliXitong.Models.Ingredient

@{
    ViewData["Title"] = "编辑食材";
}

<h2>编辑食材</h2>

<form asp-action="Edit">
    <div asp-validation-summary="ModelOnly" class="text-danger"></div>
    <input type="hidden" asp-for="Id" />
    <input type="hidden" asp-for="CreatedTime" />
    <div class="form-group">
        <label asp-for="Category" class="control-label">类别</label>
        <input asp-for="Category" class="form-control" />
        <span asp-validation-for="Category" class="text-danger"></span>
    </div>
    <div class="form-group">
        <label asp-for="Name" class="control-label">食材名称</label>
        <input asp-for="Name" class="form-control" />
        <span asp-validation-for="Name" class="text-danger"></span>
    </div>
    <div class="form-group">
        <label asp-for="Specification" class="control-label">规格</label>
        <input asp-for="Specification" class="form-control" />
        <span asp-validation-for="Specification" class="text-danger"></span>
    </div>
    <div class="form-group">
        <label asp-for="Unit" class="control-label">单位</label>
        <input asp-for="Unit" class="form-control" />
        <span asp-validation-for="Unit" class="text-danger"></span>
    </div>
    <div class="form-group">
        <label asp-for="Price" class="control-label">单价</label>
        <input asp-for="Price" class="form-control" />
        <span asp-validation-for="Price" class="text-danger"></span>
    </div>
    <div class="form-group">
        <label asp-for="Remark" class="control-label">备注</label>
        <input asp-for="Remark" class="form-control" />
        <span asp-validation-for="Remark" class="text-danger"></span>
    </div>
    <div class="form-group">
        <label asp-for="CreatedTime" class="control-label">创建时间</label>
        <input asp-for="CreatedTime" class="form-control" readonly />
        <span asp-validation-for="CreatedTime" class="text-danger"></span>
    </div>
    <div class="form-group">
        <label asp-for="UpdatedTime" class="control-label">修改时间</label>
        <input asp-for="UpdatedTime" class="form-control" readonly />
        <span asp-validation-for="UpdatedTime" class="text-danger"></span>
    </div>
    <div class="form-group">
        <input type="submit" value="保存" class="btn btn-primary" />
        <a asp-action="Index" class="btn btn-secondary">返回列表</a>
    </div>
</form>

@section Scripts {
    @{await Html.RenderPartialAsync("_ValidationScriptsPartial");}
    
    <script>
        // 在页面加载时设置修改时间为当前时间
        document.addEventListener('DOMContentLoaded', function() {
            const updatedTimeInput = document.getElementById('UpdatedTime');
            if (updatedTimeInput) {
                const now = new Date();
                updatedTimeInput.value = now.getFullYear() + '-' + 
                    String(now.getMonth() + 1).padStart(2, '0') + '-' + 
                    String(now.getDate()).padStart(2, '0') + ' ' + 
                    String(now.getHours()).padStart(2, '0') + ':' + 
                    String(now.getMinutes()).padStart(2, '0') + ':' + 
                    String(now.getSeconds()).padStart(2, '0');
            }
        });
    </script>
}